package com.cf.auth;

import com.cf.auth.controller.SpiderAuthController;
import com.cf.auth.controller.SpiderAuthItemController;
import com.cf.auth.model.service.AuthItemService;
import com.cf.auth.model.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * boot-awm-SpiderAuthConfig
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/7/11 上午 11:12
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(SpiderAuthProperty.class)
public class SpiderAuthAdminConfig implements InitializingBean {

    @Bean
    public SpiderAuthController spiderAuthController() {
        log.info("实例化SpiderAuthController");
        return new SpiderAuthController();
    }

    @Bean
    public SpiderAuthItemController spiderAuthItemController() {
        log.info("实例化SpiderAuthItemController");
        return new SpiderAuthItemController();
    }


    @Autowired
    private FreeMarkerProperties freeMarkerProperties;

    @Override
    public void afterPropertiesSet() throws Exception {
        String[] templateLoaderPath = freeMarkerProperties.getTemplateLoaderPath();
        ArrayList<String> paths = new ArrayList();
        paths.addAll(Arrays.asList(templateLoaderPath));
        paths.add("classpath:/template-auth/");
        String[] strings = paths.toArray(new String[paths.size()]);
        freeMarkerProperties.setTemplateLoaderPath(strings);
    }


}
